package com.sillyhat.optimize.chapter.two.AvoidNewInstance.success;

import com.sillyhat.optimize.chapter.two.AvoidNewInstance.error.AvoidNewInstanceError;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * 2.5  避免创建不必要的对象
 *
 * @author 徐士宽
 * @date 2017/1/13 10:49
 */
public class AvoidNewInstanceSuccess {

    private static Date BOOM_START = null;

    private static Date BOOM_END = null;

    static{
        Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        gmtCal.set(2015,Calendar.JANUARY,1,0,0,0);
        BOOM_START = gmtCal.getTime();
        gmtCal.set(2018,Calendar.JANUARY,1,0,0,0);
        BOOM_END = gmtCal.getTime();
    }

    //校验某日期是否处于数字年份之间
    public boolean isBabyBoomer(Date birthday){
        return birthday.compareTo(BOOM_START) >= 0 && birthday.compareTo(BOOM_END) < 0;
    }

}